
function y = difD3_MultiObj(w,t,P,X,Z,R,C)

y = zeros(t,1);
% PZZ = calculatePHat_fixedW(w,t,X,Z,R,C);
PZZ = calculatePHat_fixedW(w,t,X,Z,R,C);
for i = 1: t
    
    PP(:,:) = P(i,:,:);
    PZZZ(:,:) = PZZ(i,:,:);
    
    for ii=1:R
        for jj=1:C
            if jj~= C
                y(i) = y(i) + myfunc(ii,jj,PP,PZZZ);
            else
                y(i) = y(i) + myfunc(ii,jj,PP,PZZZ)*C;
            end
        end
    end
    
    y(i) = abs(y(i));
end

end



function v = myfunc(ii,jj,P,PZ)

p = P(ii,jj);
pHat = PZ(ii,jj);

v = (ii - jj)* sign(p - pHat)*(p - pHat)^2;

% if pHat ~=0
%     v = (ii - jj)* sign(p(ii, jj) - pHat(ii, jj))*(p(ii, jj) - pHat(ii, jj))^2;
% else
%     v = 0;
% end

end

